package com.burst.reptile.modular.api.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.burst.reptile.common.utils.poi.ExcelUtil;
import com.burst.reptile.framework.aspectj.lang.annotation.DelRes;
import com.burst.reptile.framework.web.controller.BaseController;
import com.burst.reptile.framework.web.result.LayuiResult;
import com.burst.reptile.framework.web.result.Result;
import com.burst.reptile.modular.api.form.QueryResForm;
import com.burst.reptile.modular.zp.entity.ZpResources;
import com.burst.reptile.modular.zp.service.IZpResourcesService;
import com.burst.reptile.modular.zp.warpper.ZpResourcesWrapper;

import lombok.RequiredArgsConstructor;

/**
 * 资源管理控制器
 * @author wujin
 *
 * @date: 2020年7月3日 上午9:44:55
 */
@RestController
@RequestMapping("/zp/data")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ZpDataController extends BaseController{

	private final IZpResourcesService resourcesService;
	
	/**
	 * 获取资源列表
	 * @param resources
	 * @return
	 */
	@GetMapping("/list")
	@PreAuthorize("@ss.hasPermi('zp:data:list')")
	public LayuiResult<Object> list(QueryResForm query){
		Page<ZpResources> page = startPage();
		Page<ZpResources> myPageList = resourcesService.myPageList(page, query);
		new ZpResourcesWrapper(myPageList).wrap();
		return LayuiResult.success(myPageList.getTotal(), myPageList.getRecords());
	}
	
	/**
	 * 加入推荐
	 * @param ids
	 * @return
	 */
	@PostMapping("/recommend/{ids}")
	@PreAuthorize("@ss.hasPermi('zp:data:rec')")
	public Result<Object> recommend(@PathVariable Long[] ids){
		return Result.success(resourcesService.recommend(ids));
	}
	
	/**
	 * 取消推荐
	 * @param ids
	 * @return
	 */
	@PostMapping("/unrecommend/{ids}")
	@PreAuthorize("@ss.hasPermi('zp:data:rec')")
	public Result<Object> unrecommend(@PathVariable Long[] ids){
		return Result.success(resourcesService.unrecommend(ids));
	}
	
	/**
	 * 删除
	 * @param ids
	 * @return
	 */
	@DeleteMapping("/remove/{ids}")
	@PreAuthorize("@ss.hasPermi('zp:data:remove')")
	@DelRes
	public Result<Object> remove(@PathVariable Long[] ids){
		return Result.success(resourcesService.delById(ids));
	}
	
	/**
	 * 导出信息数据
	 * @param dictData
	 * @return
	 */
	@PreAuthorize("@ss.hasPermi('zp:data:export')")
	@GetMapping("/export")
	public Result<Object> export(QueryResForm query) {
		List<ZpResources> list = resourcesService.selectDataList(query);
		ExcelUtil<ZpResources> util = new ExcelUtil<ZpResources>(ZpResources.class);
		return util.exportExcel(list, "信息数据");
	}
	
}
